//
//  cloud.m
//  cloud
//
//  Created by rimi on 16/3/16.
//  Copyright © 2016年 com.ruifeng. All rights reserved.
//

#import "Cloud.h"

@implementation Cloud
-(UIImageView *)cloud{
    if (!_cloud) {
        _cloud = [[UIImageView alloc]init];
        _cloud.image = [UIImage imageNamed:@"云"];
    }
    return _cloud;
}
- (UIView *)mask{
    if (!_mask) {
        _mask = [[UIView alloc]init];
        _mask.backgroundColor = [UIColor whiteColor];
    }
    return _mask;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self start];
    }
    return self;
}

- (void)start{
    UIImageView *rain1 = [[UIImageView alloc]init];
    rain1.frame = CGRectMake(0.13*self.frame.size.width+0.2*self.frame.size.width*0, 0.3*self.frame.size.height, self.frame.size.width*0.12, self.frame.size.width*0.12);
    rain1.image = [UIImage imageNamed:@"rain"];
    [self addSubview:rain1];
    [UIView animateWithDuration:1.8 delay:0 options:UIViewAnimationOptionRepeat animations:^{
        CGPoint rainCenter = rain1.center;
        
        rainCenter.y += 60;
        rain1.center = rainCenter;
    } completion:nil];
    
    
    UIImageView *rain2 = [[UIImageView alloc]init];
    rain2.frame = CGRectMake(0.13*self.frame.size.width+0.2*self.frame.size.width*1, 0.3*self.frame.size.height, self.frame.size.width*0.12, self.frame.size.width*0.12);
    rain2.image = [UIImage imageNamed:@"rain"];
    [self addSubview:rain2];
    [UIView animateWithDuration:1.8 delay:0.4 options:UIViewAnimationOptionRepeat animations:^{
        CGPoint rainCenter = rain2.center;
        rainCenter.y += 60;
        rain2.center = rainCenter;
    } completion:nil];
    
    UIImageView *rain3 = [[UIImageView alloc]init];
    rain3.frame = CGRectMake(0.13*self.frame.size.width+0.2*self.frame.size.width*2, 0.3*self.frame.size.height, self.frame.size.width*0.12, self.frame.size.width*0.12);
    rain3.image = [UIImage imageNamed:@"rain"];
    [self addSubview:rain3];
    [UIView animateWithDuration:1.8 delay:0.8 options:UIViewAnimationOptionRepeat animations:^{
        CGPoint rainCenter = rain3.center;
        rainCenter.y += 60;
        rain3.center = rainCenter;
    } completion:nil];
    self.cloud.frame = CGRectMake(0, 0, self.frame.size.width*0.84, self.frame.size.height*0.54);
    [self addSubview:_cloud];
    [UIView animateWithDuration:12 delay:0 options:(UIViewAnimationOptionAutoreverse) animations:^{
        CGPoint cloudCenter = _cloud.center;
        cloudCenter.x += self.frame.size.width*0.1;
        _cloud.center = cloudCenter;
        
    } completion:^(BOOL finished){
        self.cloud.frame = CGRectMake(0, 0, self.frame.size.width*0.9, self.frame.size.height/2);
    }];

    
    
    
    
    
    
    self.mask.frame = CGRectMake(0, self.frame.size.height*0.87, self.frame.size.width, self.frame.size.height*0.3);
    [self addSubview:self.mask];

    
    UIImageView *ripples1 = [[UIImageView alloc]initWithFrame:CGRectMake(0.1*self.frame.size.width+0.23*self.frame.size.width*0, 0.88*self.frame.size.height, self.frame.size.width*0.03, self.frame.size.height*0.01)];
            ripples1.alpha = 0;
    ripples1.image = [UIImage imageNamed:@"水圈"];
    [self addSubview:ripples1];
    [UIView animateWithDuration:1.4 delay:0.4 options:(UIViewAnimationOptionRepeat)animations:^{
        ripples1.bounds = CGRectMake(0, 0, 20, 10);
        ripples1.alpha = 1;
      
    } completion:^(BOOL finished){
        ripples1.alpha = 0;
        
    }];
    
    UIImageView *ripples2 = [[UIImageView alloc]initWithFrame:CGRectMake(0.1*self.frame.size.width+0.3*self.frame.size.width*1, 0.88*self.frame.size.height, self.frame.size.width*0.03, self.frame.size.height*0.01)];
            ripples2.alpha = 0;
    ripples2.image = [UIImage imageNamed:@"水圈"];
    [self addSubview:ripples2];
    [UIView animateWithDuration:1.2 delay:1 options:(UIViewAnimationOptionRepeat) animations:^{
        ripples2.bounds = CGRectMake(0, 0, 20, 10);
        ripples2.alpha = 1;
    } completion:^(BOOL finished){
        ripples2.alpha = 0;
        
    }];
    
    UIImageView *ripples3 = [[UIImageView alloc]initWithFrame:CGRectMake(0.1*self.frame.size.width+0.3*self.frame.size.width*2, 0.88*self.frame.size.height, self.frame.size.width*0.03, self.frame.size.height*0.01)];
            ripples3.alpha = 0;
    ripples3.image = [UIImage imageNamed:@"水圈"];
    [self addSubview:ripples3];
    [UIView animateWithDuration:1.2 delay:1.4 options:(UIViewAnimationOptionRepeat) animations:^{
        ripples3.bounds = CGRectMake(0, 0, 20, 10);
        ripples3.alpha = 1;
    } completion:^(BOOL finished){
        ripples3.alpha = 0;
        
    }];
}
//控件消失响应动画
- (void)disMiss{
    [UIView animateWithDuration:0.5 animations:^{
        self.transform = CGAffineTransformMakeScale(0.1, 0.1);
        self.alpha = 0;
    } completion:^(BOOL finished){
        [self removeFromSuperview];
    }];
}


@end
